package nf.action;

import nf.dao.CellPhoneDao;
import nf.dao.CellPhoneDaoImpl;
import nf.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/upuserServlet")
public class upuserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("utf-8");
            String name = request.getParameter("name");
            String username1 = request.getParameter("username");
            String password1 = request.getParameter("password");


            CellPhoneDao dao = new CellPhoneDaoImpl();
            User user1 = dao.selectByName(name);
            if (user1 != null) {
                User user = new User();
                user.setName(name);
                user.setUserName(username1);
                user.setPassword(password1);
                CellPhoneDao dao1 = new CellPhoneDaoImpl();
                dao1.updateUser(user);
                response.sendRedirect("index.jsp");
            } else {
                response.sendRedirect("upuser.jsp");
            }
        }
    }

